﻿using HuiZe.education.Common;
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;

namespace HuiZe.education.Resource.Controls
{
    /// <summary>
    /// PageManager.xaml 的交互逻辑
    /// </summary>
    public partial class mySpaceEdit : UserControl
    {

        public string NomalImage { get; set; }
        public string Labtext { get; set; }
        public string Id { get; set; }
        public bool IsSelectd { get; set; } = false;
        public string IsSelectdImgUrl { get; set; }
        public mySpaceEdit()
        {
            InitializeComponent();
            Loaded += PageManager_Loaded;
        }
        private void PageManager_Loaded(object sender, RoutedEventArgs e)
        {
            Image image = new Image(); 
            image.Source = new BitmapImage(new Uri(NomalImage, UriKind.Absolute));
            image.Stretch = Stretch.Fill;
            BookImg.Source = image.Source;
            BookName.Content = Labtext;
            //deleteButton.ImageSource = new BitmapImage(new Uri(IsSelectdImgUrl, UriKind.Absolute));
        }

         private  void RadioButton_Click(object sender, RoutedEventArgs e)
        {
            CustomRadioButton customRadioButton = sender as CustomRadioButton;
            //CurrentIndex = customRadioButton.Index;
        }

        private void UserControl_FocusableChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
        }

        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {

        }

        private void BookImg_MouseDown(object sender, MouseButtonEventArgs e)
        {
          
            //var WrapParent = this.Parent as WrapPanel;
            //foreach (var control in WrapParent.Children)
            //{
            //    if (control == this)
            //    {
            //        if (deleteButton.Source == null)
            //        {
            //            IsSelectdImgUrl = "../Images/Home/Selected.png";
            //            deleteButton.Source = new BitmapImage(new Uri(IsSelectdImgUrl, UriKind.RelativeOrAbsolute));
            //            IsSelectd = true;

            //        }
            //        else
            //        {
            //            IsSelectdImgUrl = "";
            //            deleteButton.Source = null;
            //            IsSelectd = false;
            //        }
                  
            //    }
            //    else
            //    {
                   
            //    }

            //}

        }

        private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
        {

        }

        private void UserControl_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            var WrapParent = this.Parent as WrapPanel;
            if (CommonMethods.MySpaceSelectedId == null)
                CommonMethods.MySpaceSelectedId = new System.Collections.Generic.List<string>();
            foreach (var control in WrapParent.Children)
            {
                if (control == this)
                {
                    if (deleteButton.Source == null)
                    {
                       
                        IsSelectdImgUrl = "../Images/Home/Selected.png";
                        deleteButton.Source = new BitmapImage(new Uri(IsSelectdImgUrl, UriKind.RelativeOrAbsolute));
                        IsSelectd = true;
                        CommonMethods.MySpaceSelectedId.Add(Id);
                    }
                    else
                    {
                        IsSelectdImgUrl = "";
                        deleteButton.Source = null;
                        IsSelectd = false;
                        CommonMethods.MySpaceSelectedId.Remove(Id);
                    }

                }
                else
                {

                }

            }
        }
    }
}
